//npm install request
var request = require("request");
var fs = require("fs");
var http = require("http");
var ou = require("./../objectUtil.js");

var stream = fs.createWriteStream('d:/jy_index7.png');
stream.on("finish", function(data){
    console.log("结束:" + data);
});
console.log("开始");
request("https://github.com/dipoo/egdownloader/raw/master/ui.png")
       .pipe(stream);

/*
request('http://static.oschina.net/uploads/img/201407/10140010_n9nz.png', function (error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log("保存图片中");
        response.req.pipe(fs.createWriteStream('d:/haha.png'));
        console.log("保存成功");
        ou.allMembers(response);
    }
 });
*/


/*
request({
  url : "http://www.exhentai.org/",
  // jar : j,
  headers : {
    'User-Agent': 'request',
    "cookie" : "igneous=4baadb8381b3bb5c20257b33b725e4ec93f51b4fe2ab7e97621c9fe260bbda7de47a44d6394b31783a0af329a20197c80d2ab687ccf0b667ca5c558ee1b9310b;ipb_member_id=1059070;ipb_pass_hash=e8e36f507753214279ee9df5d98c476c"
    }
}, function(error, response, body){
  if(error)
    throw error;
  if(!error && response.statusCode == 200){
    // console.log(response.toJSON());
    var content_type = response.toJSON().headers['content-type'];
    if(content_type && content_type.indexOf("text/html") != -1){
      fs.writeFile("d:/haha.txt", response.body, function(){
          console.log("success!");
      });
    }
    // var cookie_str = j.getCookieString("http://www.exhentai.org/");
    // console.log(cookie_str);
  }
});
*/